https://bayton.org/2016/07/installing-nextcloud-on-ubuntu-16-04-lts-with-redis-apcu-apache/
Much like theming, pretty links aren’t mandatory, but they add to the overall aesthetics of the server.
Most of the hard work was already done during the setup of the environment with the enabling of mod_env and mod_rewrite, however to complete the removal of index.php in every URL:
1. Open the Nextcloud config file:
$ sudo nano /var/www/html/nextcloud/config/config.php
Add below one of the existing configuration options (e.g. at the bottom before the parenthesis and colon):
'htaccess.RewriteBase' => '/nextcloud',
Ctrl+x, then ‘Y' to save and exit.
Then,
$ cd /var/www/html/nextcloud
$ sudo -u www-data php occ maintenance:update:htaccess
To verify that it works, remove index.php from the URL (for example, the admin page) and load the page again.